module SOD
  
  class SGhash
    
    attr_accessor :bar_hash

    def initialize

    	SGhash.init_default_bar if not @default_bar_initialized
	    @bar_hash = SGhash.new_default_bar
	    Plugin.sgdata.bars.push(self)
    end
    
    def init_hash
      
    end
    
	def delete_from_bars
		Plugin.sgdata.bars.delete(self)
	end

    def update_by_model(model)
      
      #self.sketchInfo -> footpintLength, footprintWidth, direction, footprintPoints
      #self.barInfo -> roomsize, flexibility, numberOfStoreys, minRoomHeight /
      #-> minConstructionHeight, overallHeight, totalHeight, (update_values)?

      bar_hash[:fp_wdt] = model.sketchInfoContainer.footprintWidth.to_m.to_f
      bar_hash[:fp_lng] = model.sketchInfoContainer.footprintLength.to_m.to_f
      bar_hash[:fx_hgh] = model.projectInfo.minConstructionHeight.to_mm.to_i
      bar_hash[:rm_hgh] = model.projectInfo.minRoomHeight.to_mm.to_i

      bar_hash[:n_stys] = model.projectInfo.numberOfStoreys # number of storeys
      # rb_bar[:clzn_r] = []
      puts "bar_hash[:fp_wdt] - " + bar_hash[:fp_wdt].to_s
      puts "bar_hash[:fp_lng] - " + bar_hash[:fp_lng].to_s
      puts "bar_hash[:n_stys] - " + bar_hash[:n_stys].to_s

      Plugin.sgdata.update(self)
    end



    def self.new_default_bar
      @default_bar.dup
    end

    def self.init_default_bar 
      @default_bar = Hash.new
      # @default_bar[:bar_id] = :NO_ID
      @default_bar[:fp_lng] = 0.0 # Plugin.model.sketchInfoContainer.footprintWidth.to_m.to_f # length of the footprint
      @default_bar[:fp_wdt] = 0.0 # Plugin.model.sketchInfoContainer.footprintLength.to_m.to_f # width of the footprint
      @default_bar[:cl_sps] = [] # possible column spacing
      @default_bar[:co_hgh] = 600 # construction height
      @default_bar[:fx_hgh] = 300 #? \
      @default_bar[:rm_hgh] = 2500 
        # Plugin.model.projectInfo.minConstructionHeight.to_mm.to_i : 300# flexibility height
      @default_bar[:n_stys] = 1 # number of storeys
      @default_bar[:n_rows] = [1] # number of rows
      @default_bar[:dircts] = [0,1] # possible primary beam directions
      @default_bar[:fd_wdt] = [1.2] # facade width
      @default_bar[:p_muta] = 0.05 # mutation probability
      @default_bar[:p_crss] = 0.95 # corssover probability
      @default_bar[:p_size] = 800 # population size
      @default_bar[:nof_gn] = 1500 # nof generations
      @default_bar[:fitnss] = 0.0# fitness
      # clzn_0 = Plugin.model.sketchInfoContainer.footprintWidth.to_m.to_f * 0.4
      # clzn_1 = Plugin.model.sketchInfoContainer.footprintWidth.to_m.to_f * 0.4
      @default_bar[:clzn_r] = [0.0, 0.0]# column zone range low and heigh bound
      @default_bar[:clsp_r] = [3.0,10.0] # column spacing range low and heigh bound

      #results
      # @default_bar[:db_rdy] = false# database ready
      @default_bar[:opt_st] = OPT_STATUS_STOPED # opt_status
      @default_bar[:ps_col] = 0.0# position of inner columns
      @default_bar[:gn_str] = [] # gene string
      @default_bar[:bm_hgh] = -1.0
      @default_bar[:sl_hgh] = -1.0
      @default_bar[:g_r_vc] = 0.0 # volume concrete
      @default_bar[:g_r_mr] = 0.0 # mass reinforcement steel
      @default_bar[:g_r_mp] = 0.0 # mass profiled sheeting
      @default_bar[:g_r_mq] = 0.0 # mass structure steel
      @default_bar[:g_r_aa] = 0.0 # area steel coating 
      # @default_bar[:slcted] = false

      @default_bar.each{ |k,v| v.freeze }
      @default_bar.freeze
      @default_bar_initialized = true
    end

    def fitness ( rb_bar = @active_bar)
      rb_bar[:fitnss]
    end
    def position_of_inner_columns ( rb_bar = @active_bar)
      rb_bar[:ps_col]
    end
    def genes_string ( rb_bar = @active_bar)
      rb_bar[:gn_str]
    end
    def opt_status ( rb_bar = @active_bar)
      rb_bar[:opt_st]
    end

    
  end
  
end
